﻿ <!--
  Odatavalidator ver. 1.0
  Copyright (c) Microsoft Corporation
  All rights reserved.

  Licensed under the Apache License, Version 2.0 (the ""License"");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

  THIS CODE IS PROVIDED ON AN  *AS IS* BASIS, WITHOUT WARRANTIES OR
  CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT
  LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS
  FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT.

  See the Apache Version 2.0 License for specific language governing
  permissions and limitations under the License.
-->

<rules>
  <rule id="Entry.Core.4645" category="core" target="entry" v4specificationsection="8.2.1.1" version="v3_v4" requirementlevel="must" format="atom">
    <description>The rel attribute of atom:link element for association link MUST be present.</description>
    <action processor="rng">
      <grammar xmlns="http://relaxng.org/ns/structure/1.0" xmlns:atom="http://www.w3.org/2005/Atom">
        <start>
          <element name="atom:entry">
            <interleave>
              <zeroOrMore>
                <choice>
                  <element name="atom:link">
                    <attribute name="rel" />
                    <attribute name="type">
                      <value>application/xml</value>
                    </attribute>
                    <ref name="anyAttributes_without_name_ref_or_type" />
                  </element>
                  <ref name="anyElement_of_link_other_than_association_link" />
                </choice>
              </zeroOrMore>
            </interleave>
            <ref name="anyContentNotElements" />
          </element>
        </start>
        <define name="anyAttributes_without_name_ref_or_type">
          <zeroOrMore>
            <attribute>
              <anyName>
                <except>
                  <name>rel</name>
                  <name>type</name>
                </except>
              </anyName>
            </attribute>
          </zeroOrMore>
        </define>
        <define name="anyAttribute_without_association_flag">
          <choice>
            <attribute>
              <anyName>
                <except>
                  <name>type</name>
                </except>
              </anyName>
            </attribute>
            <attribute>
              <name>type</name>
              <data type="string">
                <except>
                  <value>application/xml</value>
                </except>
              </data>
            </attribute>
          </choice>
        </define>
        <define name="anyElement">
          <element>
            <anyName />
            <zeroOrMore>
              <choice>
                <attribute>
                  <anyName />
                </attribute>
                <text />
                <ref name="anyElement" />
              </choice>
            </zeroOrMore>
          </element>
        </define>
        <define name="anyElement_of_link_other_than_association_link">
          <choice>
            <element>
              <anyName />
              <zeroOrMore>
                <choice>
                  <ref name="anyAttribute_without_association_flag" />
                  <text />
                  <ref name="anyElement" />
                </choice>
              </zeroOrMore>
            </element>
            <element>
              <anyName>
                <except>
                  <name>atom:link</name>
                </except>
              </anyName>
              <interleave>
                <attribute name="type">
                  <value>application/xml</value>
                </attribute>
                <zeroOrMore>
                  <attribute>
                    <anyName>
                      <except>
                        <name>type</name>
                      </except>
                    </anyName>
                  </attribute>
                </zeroOrMore>
              </interleave>
              <zeroOrMore>
                <choice>
                  <text />
                  <ref name="anyElement" />
                </choice>
              </zeroOrMore>
            </element>
          </choice>
        </define>
        <define name="anyContentNotElements">
          <zeroOrMore>
            <choice>
              <attribute>
                <anyName />
              </attribute>
              <text />
            </choice>
          </zeroOrMore>
        </define>
      </grammar>
    </action>
    <errormessage>The rel attribute of atom:link element for association link MUST be present.</errormessage>
  </rule>
</rules>